﻿using System;
using System.ComponentModel;

using DevExpress.Xpo;

using DevExpress.ExpressApp;
using DevExpress.ExpressApp.SystemModule;


namespace SpeedSCM.Module
{
    public enum 单据状态
    {
        未执行 = 0,
        已执行 = 1
    }

    [DefaultProperty("单据编号")]
    [ListViewFilter("我的今天未执行单据", "[经手人] ='@CurrentUserID' AND GetDate([录单日期]) = '@CurrentDate' AND [单据状态]= 0", true, Index = 0)]
    [ListViewFilter("我的今天已执行单据", "[经手人] ='@CurrentUserID' AND GetDate([录单日期]) = '@CurrentDate' AND [单据状态]= 1", Index = 1)]

    [ListViewFilter("我的三天内未执行单据", "[经手人] ='@CurrentUserID' AND GetDate([录单日期]) >= ADDDAYS('@CurrentDate', -3) AND GetDate([录单日期]) <= ('@CurrentDate') AND [单据状态]= 0", Index = 2)]
    [ListViewFilter("我的三天内已执行单据", "[经手人] ='@CurrentUserID' AND GetDate([录单日期]) >= ADDDAYS('@CurrentDate', -3) AND GetDate([录单日期]) <= ('@CurrentDate') AND [单据状态]= 1", Index = 3)]

    [ListViewFilter("我的本周未执行单据", "[经手人] ='@CurrentUserID' AND GetDate([录单日期]) >= ADDDAYS('@LastWorkWeekStart', 7) AND GetDate([录单日期]) <= ADDDAYS('@LastWorkWeekEnd', 7) AND [单据状态]= 0", Index = 4)]
    [ListViewFilter("我的本周已执行单据", "[经手人] ='@CurrentUserID' AND GetDate([录单日期]) >= ADDDAYS('@LastWorkWeekStart', 7) AND GetDate([录单日期]) <= ADDDAYS('@LastWorkWeekEnd', 7) AND [单据状态]= 1", Index = 5)]

    [ListViewFilter("我的上周未执行单据", "[经手人] ='@CurrentUserID' AND GetDate([录单日期]) >= '@LastWorkWeekStart' AND GetDate([录单日期]) <= '@LastWorkWeekEnd' AND [单据状态]= 0", Index = 6)]
    [ListViewFilter("我的上周已执行单据", "[经手人] ='@CurrentUserID' AND GetDate([录单日期]) >= '@LastWorkWeekStart' AND GetDate([录单日期]) <= '@LastWorkWeekEnd' AND [单据状态]= 1", Index = 7)]

    [ListViewFilter("我的两周未执行内单据", "[经手人] ='@CurrentUserID' AND GetDate([录单日期]) >= ADDDAYS('@CurrentDate', -14) AND GetDate([录单日期]) <= ('@CurrentDate') AND [单据状态]= 0", Index = 8)]
    [ListViewFilter("我的两周内已执行单据", "[经手人] ='@CurrentUserID' AND GetDate([录单日期]) >= ADDDAYS('@CurrentDate', -14) AND GetDate([录单日期]) <= ('@CurrentDate') AND [单据状态]= 1", Index = 9)]

    [ListViewFilter("我的所有未执行单据", "[经手人] ='@CurrentUserID' AND [单据状态]= 0", Index = 10)]
    [ListViewFilter("我的所有已执行单据", "[经手人] ='@CurrentUserID' AND [单据状态]= 1", Index = 11)]
    [ListViewFilter("我的所有单据", "[经手人] ='@CurrentUserID'", Index = 12)]
    public abstract class 单据 : 基础
    {
        public 单据(Session session)
            : base(session)
        {

        }
        public override void AfterConstruction()
        {
            base.AfterConstruction();
            录单日期 = DateTime.Now;
            单据编号 = ConstSeedNum.EmptyOrderNO;
            经手人 = Session.GetObjectByKey<职员>(SecuritySystem.CurrentUserId);
            单据状态 = 单据状态.未执行;
        }
        protected override void OnSaving()
        {
            base.OnSaving();
            if (Session.IsNewObject(this))
            {
                if (单据编号 == ConstSeedNum.EmptyOrderNO)
                {
                    单据编号 = SeedNum.GetSeedNum(Session, SeedType);
                }
            }
        }
        [Custom("Caption", "单据类型")]
        protected abstract SeedType SeedType { get; }
        private DateTime _录单日期;
        [Custom("Caption", "录单日期")]
        [Custom("AllowEdit", "False")]
        public DateTime 录单日期
        {
            get { return _录单日期; }
            set { SetPropertyValue<DateTime>("录单日期", ref _录单日期, value); }
        }
        private string _单据编号;
        [Custom("Caption", "单据编号")]
        [Custom("AllowEdit", "False")]
        public string 单据编号
        {
            get { return _单据编号; }
            set { SetPropertyValue<string>("单据编号", ref _单据编号, value); }
        }
        private 职员 _经手人;
        [Custom("Caption", "经手人")]
        public 职员 经手人
        {
            get { return _经手人; }
            set { SetPropertyValue<职员>("经手人", ref _经手人, value); }
        }
        private string _附加说明;
        [Custom("Caption", "附加说明")]
        [Size(500)]
        public string 附加说明
        {
            get { return _附加说明; }
            set { SetPropertyValue<string>("附加说明", ref _附加说明, value); }
        }

        private string _摘要;
        [Custom("Caption", "摘要")]
        [Size(500)]
        public string 摘要
        {
            get { return _摘要; }
            set { SetPropertyValue<string>("摘要", ref _摘要, value); }
        }

        private 单据状态 _单据状态;
        [Custom("Caption", "单据状态")]
        [Custom("AllowEdit", "False")]
        public 单据状态 单据状态
        {
            get { return _单据状态; }
            set { SetPropertyValue<单据状态>("单据状态", ref _单据状态, value); }
        }
        /// <summary>
        /// 执行对状态的更新
        /// </summary>
        /// <param name="objectSpace"></param>
        /// <returns></returns>
        public virtual bool Excute(IObjectSpace objectSpace)
        {
            return true;
        }
    }
}
